window.onload = function () {
// $(function () {
    var $cartS = Number($(".sidebox_span2_3").text());

    $(document).on("click", ".put_cart", function () {
        var $cloneA = $(this).clone(true);
        var position = $(this).offset();
        $cloneA.css({
            "position": "absolute",
            "left": position.left,
            "top": position.top,
            "height": "38px",
            "width": "38px",
            "border-radius": "50%",
            "backgroundColor": "#ff643c",
            "zIndex": 999
        })
        $cloneA.text("")
        $(this).parents("body").append($cloneA);
        var $target = $(".sidebox_span2_1").offset();
        $cloneA.fly({
            start: {
                left: position.left - $(document).scrollLeft(),
                top: position.top - $(document).scrollTop()
            },
            end: {
                left: $target.left - $(document).scrollLeft(),
                top: $target.top - $(document).scrollTop()
            },
            onEnd: function () {
                // $cloneA.show().animate({width: '200px'},300).fadeOut(500);
                this.destroy();
                $(".sidebox_span2_3").text($cartS += 1);
                if ($cartS > 0) {
                    $(".header_shopgoods_totleamout").text($cartS).css("display", "block");
                } else {
                    $(".header_shopgoods_totleamout").text($cartS).css("display", "none");
                }
            }
        })
        console.log($(this).attr("data"));
        var $info = $(this).attr("data");
        var arrInfo = $info.split("_");
        console.log(arrInfo);
        var oBj = {};
        oBj["Id"] = arrInfo[0];
        oBj["Info"] = arrInfo[1];
        oBj["Price"] = arrInfo[2];
        oBj["oNumber"] = Number(arrInfo[3]);
        var CookieArr = JSON.parse($.getCookie("shop_cart") || `[]`);
        // console.log(CookieArr[0]["oNumber"]);

        var bflag = true;
        for (var i = 0; i < CookieArr.length; i++) {
            if (CookieArr[i]["Id"] == oBj["Id"]) {
                CookieArr[i]["oNumber"] += 1;
                bflag = false;
                break;
            }
        }
        console.log(CookieArr);
        if (bflag) {
            CookieArr.push(oBj);
        }


        // console.log(CookieArr[0]["oNumber"]);
        // console.log(oBj);

        var StrArr = JSON.stringify(CookieArr);
        $.SetCookie("shop_cart", StrArr, 10);
        // console.log($.getCookie("shop_cart"));
        return false;
    })

    // $.getCookie("shop_cart")
// })

}
